package cn.weisoft.nconv.controller;

import cn.weisoft.nconv.model.Garden;
import cn.weisoft.nconv.model.GardenPara;
import cn.weisoft.nconv.model.GardenRet;
import cn.weisoft.nconv.service.GardenService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(value = "花园信息", description = "花园操作 API", position = 100, protocols = "http")
@RestController
@RequestMapping("/garden")
@CrossOrigin(origins = "*",allowedHeaders = "*",allowCredentials = "true")
public class GardenController {

    @Autowired
    private GardenService gardenService;

    @ApiOperation(
            value = "插入花园信息",
            notes = "插入花园信息",
            response = int.class)
    @PostMapping("insertGarden")
    public boolean saveGarden(@RequestBody Garden garden) {
        return gardenService.save(garden);
    }

    @ApiOperation(
            value = "更新花园信息",
            notes = "更新花园信息",
            response = int.class)
    @PostMapping("updateGarden")
    public boolean updateGarden(@RequestBody Garden garden) {

        return gardenService.updateById(garden);
    }

    @ApiOperation(
            value = "根据id删除",
            notes = "根据id删除",
            response = int.class)
    @GetMapping("/deleteById")
    public boolean deleteById(int id) {
        return gardenService.removeById(id);
    }


    @ApiOperation(
            value = "获取所有花园",
            notes = "获取所有花园",
            response = List.class)
    @GetMapping("/selectAllGarden")
    public List<Garden> selectAllGarden() {
        return gardenService.list();
    }

    @ApiOperation(
            value = "根据id获取",
            notes = "根据id获取",
            produces = "application/json, application/xml",
            consumes = "application/json, application/xml",
            response = Garden.class)
    @ApiImplicitParams({@ApiImplicitParam(name = "id", value = "花园ID", required = true, dataType = "Long", paramType = "query")})
    @GetMapping("getById")
    //@Cacheable(value="c3")
    public Garden getById(int id) {
        return gardenService.getById(id);
    }

    @ApiOperation(
            value = "获取指定坐标范围的花园",
            response = List.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "minLng", value = "最小经度", required = true, dataType = "Float", paramType = "query"),
            @ApiImplicitParam(name = "minLat", value = "最小纬度", required = true, dataType = "Float", paramType = "query"),
            @ApiImplicitParam(name = "maxLng", value = "最大经度", required = true, dataType = "Float", paramType = "query"),
            @ApiImplicitParam(name = "maxLat", value = "最大纬度", required = true, dataType = "Float", paramType = "query")
    })
    @GetMapping("/selectGardenByBnd")
    public List<Garden> selectGardenByBnd(float minLng, float minLat, float maxLng, float maxLat) {
        return gardenService.selectGardenByBnd(minLng, minLat, maxLng, maxLat);
    }


  /*  @ApiOperation(
            value = "根据自定义参数获取数据局",
            response = GardenRet.class)
    @PostMapping("/selectWithParam")
    public GardenRet selectWithParam(@RequestBody GardenPara garden) {
        return gardenService.selectWithParam(garden);
    }*/


    @PostMapping("/selectPage")
    public GardenRet selectPage(@RequestBody GardenPara para) {
        return gardenService.selectPage(para);
    }
}
